/*
 * Copyright 2009 XueSong Guo.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.webwheel.utils;

/**
 * 默认的页面动作类实现
 */
public class DefaultPage extends DefaultAction {

    /**
     * 返回对应于当前页面动作类的页面模板结果，通过{@link cn.webwheel.utils.TemplateResult#TemplateResult(Object)}构造。
     * @return 页面模板结果
     * @throws Exception 任何异常
     */
    public Object execute() throws Exception {
        return new TemplateResult(this);
    }

    /**
     * 将字符'<'替换为"&amp;lt;"的工具方法，在需要将某个对象显示在页面中时使用。
     * @param obj 需要显示的对象
     * @return 页面显示字符串
     */
    public String wrapC(Object obj) {
        if(obj==null) return null;
        return obj.toString().replace("<", "&lt;");
    }

    /**
     * 将字符'"'替换为"&amp;quot;"的工具方法，在需要将某个对象显示在页面中标签属性值时使用。
     * @param obj 需要显示的对象
     * @return 页面显示字符串
     */
    public String wrapA(Object obj) {
        if(obj==null) return null;
        return obj.toString().replace("\"", "&quot;");
    }
}
